package baidumodel.util;

import baidumodel.constant.ApiConstant;
import baidumodel.entity.Token;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;

/**
 * 获取token
 *
 * @Author wuchenxi
 * @Date 2023-07-29 12:10:20
 */
public class TokenUtil {
    private TokenUtil() {
    }

    public static String getToken(String appKey, String secretKey) {
        String s = HttpUtil.get(ApiConstant.getToken(appKey, secretKey));
        Token bean = JSONUtil.toBean(s, Token.class);
        if (StrUtil.isNotBlank(bean.getError())) {
            System.out.printf("获取token异常，err=%s", s);
        }
        return bean.getAccess_token();
    }
}
